<%@ page language="java" isELIgnored="false" import="java.util.*"
	pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@page import="com.testingedu.common.QueryResult"%>
<%@page import="com.testingedu.model.TRole"%>
<%QueryResult queryResult = (QueryResult) request.getAttribute("queryResult"); %>
<!-- roleAdd.jsp -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>添加用户</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/pingTai/pingTai.css">
		<script src="${pageContext.request.contextPath}/js/utils.js" type="text/javascript" language="javascript"></script>
		<SCRIPT type="text/javascript" language="javascript"  src="${pageContext.request.contextPath}/js/jquery-1.7.2.js"></SCRIPT>
		<script charset="utf-8" src="${pageContext.request.contextPath}/editor/kindeditor.js"></script>
		<script charset="utf-8" src="${pageContext.request.contextPath}/editor/lang/zh_CN.js"></script>
<script>
        var editor;
        KindEditor.ready(function(K) {
                editor = K.create('#editor_id');
        });
</script>
<script type="text/javascript">
	$(document).ready(function() {
		$('#_role').change(function() {
			if($('#_role').val() == 1) {
				$(this).after('<font color="blue" id="_font">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;在首页显示其电话号码和qq</font><input type="checkbox" name="showInfo" id="_checkbox">');
			} else {
				$('#_font').remove();
				$('#_checkbox').remove();
			}
		});
	});
</script>
	</head>
	<body>
		<table width="100%" border="0" align="center" cellpadding="0"
			cellspacing="0">
			<tr>
				<td height="3"></td>
			</tr>
			<tr height="20" valign="baseline">
				<td bgcolor="#353c44">
					<img src="${pageContext.request.contextPath}/images/pingTai/tb.gif"
						width="14" height="14" />
					<span class="STYLE1">添加用户</span>
				</td>
				<td align="right" bgcolor="#353c44">
					<span class="STYLE1"> </span>
				</td>
			</tr>
			<tr>
				<td height="3" colspan="2"></td>
			</tr>
		</table>
		<form id="_form">
			<table width="100%" border="0" cellpadding="0" cellspacing="1"
				bgcolor="#a8c7ce">
				
				<tr bgcolor="#FFFFFF" class="STYLE19">
					<td align="right" width="15%">
						姓名:
					</td>
					<td width="35%">
						<input type="text" name="name" id="_name" size="50">
					</td>
					<td align="right" width="15%">
						所属角色:
					</td>
					<td width="35%">
						<select name="roleId" id="_role">
							<option value='0'>暂无</option>
							<%
							for(int i = 0 ; i < queryResult.getResultList().size(); i++) {
								TRole tRole = (TRole)queryResult.getResultList().get(i);
							%>
								<option value="<%=tRole.getId() %>"><%=tRole.getName() %></option>
							<%} %>
						</select>
					</td>
				</tr>
				<tr bgcolor="#FFFFFF" class="STYLE19">
					<td align="right" width="15%">
						登陆名:
					</td>
					<td width="35%">
						<input type="text" name="account" id="_account" size="50">
					</td>
					<td align="right" width="15%">
						密码:
					</td>
					<td width="35%">
						<input type="password" name="password" id="_password"
							size="50">
					</td>
				</tr>
				<tr bgcolor="#FFFFFF" class="STYLE19">
					<td align="right" width="15%">
						电话号码:
					</td>
					<td width="35%">
						<input type="text" name="phone" id="_phone" size="50">
					</td>
					<td align="right" width="15%">
						性别:
					</td>
					<td width="35%">
						<select name="sex" id="_sex">
							<option value="m">
								男
							</option>
							<option value="f">
								女
							</option>
						</select>
					</td>
				</tr>
				<tr bgcolor="#FFFFFF" class="STYLE19">
					<td align="right" width="15%">
						邮箱:
					</td>
					<td width="35%" colspan="1">
						<input type="text" name="email" id="_email" size="50">
					</td>
					<td align="right" width="15%">
						QQ:
					</td>
					<td width="35%" colspan="1">
						<input type="text" name="qq" id="_qq" size="40">
					</td>
				</tr>
				<tr bgcolor="#FFFFFF" class="STYLE19">
					<td align="right">
						用户详细信息:
					</td>
					<td colspan="3">
						<textarea id="editor_id" name="description"
							style="width: 800px; height: 400px;">
						</textarea>
					</td>
				</tr>
				<tr bgcolor="#FFFFFF" class="STYLE19">
					<td colspan="4" align="center">
						<input type="button" class="button2" value="添加"
							onclick="save_to_user();"/>
						<input type="reset" class="button2" value="重置" />
						<input type="button" class="button2" value="返回"
							onclick="javascript:history.go(-1);" />
					</td>
				</tr>
			</table>
		</form>
	</body>
	<script type="text/javascript">
		function save_to_user() {
			var name = $('#_name').val();
			if(!utils_stringLength(name, '姓名', 2, 20))
				return;
			var account = $('#_account').val();
			if(!utils_stringLength(account, '登陆名', 2, 20))
				return;
			var password = $('#_password').val();
			if(!utils_stringLength(password, '密码', 4, 20))
				return;
			var phone = $('#_phone').val();
			if(!utils_stringLength(phone, '电话号码', 7, 14))
				return;
			var email = $('#_email').val();
			if(!validateEmail(email))
				return;
			var qq = $('#_qq').val();
			if(!utils_qq(qq, 'QQ', 6, 13))
				return;
			var description = $('#editor_id').val();
			if(!utils_stringLength(description, '用户详细信息', 1, 2000))
				return;
			editor.sync();
			$.ajax({
	   			type: "POST",
	   			url: "${pageContext.request.contextPath}/admin/user/add",
	   			data: $('#_form').serialize(),
	   			dataType: "json",
	   			success: function(json){
     					if(json.id > 0) {
     						window.location.href="${pageContext.request.contextPath}/admin/user/list?id="+json.id+"&url=info";
     					} else {
     						alert('添加用户失败，请重试！');
     					}
   				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
   						alert("操作时发生了错误，请重试");
					},
				});
		}
	</script>
</html>
